//
//  main.c
//  algorithm
//
//  Created by 张俊正（总行零售网金） on 2020/4/29.
//  Copyright © 2020 sunshinfight. All rights reserved.
//

#include <stdio.h>
#include "Graph.hpp"
#include "SortAlgorithm.h"

void sort(int list[], int left, int right) {
    if (left > right) {
        return;
    }
    int base = list[left];
    int i = left;
    int j = right;
    while (i != j) {
        while (list[j] >= base && i < j) {
            j--;
        }
        while (list[i] <= base && i < j) {
            i++;
        }
        if (i < j) {
            int tmp = list[i];
            list[i] = list[j];
            list[j] = tmp;
        }
    }
    list[left] = list[i];
    list[i] = base;
    sort(list, left, i - 1);
    sort(list, i + 1, right);
}


void show(int list[], int count) {
    for (int i = 0; i < count; i++) {
        printf("%d, ", list[i]);
    }
    printf("\n");
}

int main(int argc, const char * argv[]) {
    // insert code here...
    
    int list[] = {3, 5, 2, 1, 7, 6, 9, 0};
    sort(list, 0, 7);
    show(list, 8);
    
    int list1[] = {3, 5, 2, 1, 7, 6, 9, 0};

    sinkSort(list1, 8);
    show(list1, 8);
    
    int list2[] = {3, 5, 2, 1, 7, 6, 9, 0};
    simpleSelectSort(list2, 8);
    show(list2, 8);
    
    int list3[] = {3, 5, 2, 1, 7, 6, 9, 0};
    simpleInsertSort(list3, 8);
    show(list3, 8);
    
    int list4[] = {3, 5, 2, 1, 7, 6, 9, 0};
    shellSort(list4, 8);
    show(list4, 8);
    
    int list5[] = {3, 5, 2, 1, 7, 6, 9, 0};
    quickSort(list5, 0, 7);
    printf("quick sort result: \n");
    show(list5, 8);
    
    int list6[] = {3, 5, 2, 1, 7, 6, 9, 0};
    int kThMax = kThMaxValue(list6, 0, 7, 2);
    printf("find k max result: %d \n", kThMax);
    
    int list7[] = {3, 5, 2, 1, 7, 6, 9, 0};
    mergeSort(list7, 0, 7);
    printf("merge sort result: ");
    show(list7, 8);
    
    int list8[] = {3, 5, 2, 1, 7, 6, 9, 0};
    heapSort(list8, 8);
    show(list8, 8);
    
    int list9[] = {3, 5, 2, 1, 7, 6, 9, 0};
    countSort(list9, 8, 9);
    show(list9, 8);
    
    return 0;
}
